$(function(){
	$('body').on('click','#resource_submit',function(e){
		window.localStorage.clear();
		var param = {
				success: function (data) {
					var call_back_value =$("#call_back").val();
					parent.eval(call_back_value)(data); 
					var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
			        parent.layer.close(index);
					//return data;
				}
		}
		$.getResource(param)
		
	})
	
	$('body').on('click','#resource_submit_news',function(e){
		var param = {
				success: function (data) {
					var call_back_value =$("#call_back").val();
					parent.eval(call_back_value)(data); 
					var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
			        parent.layer.close(index);
					//return data;
				}
		}
		$.getResourceNews(param)

		window.localStorage.clear();
	})
	
	$('body').on('click','#resource_submit_live',function(e){
		var param = {
				success: function (data) {
					var call_back_value =$("#call_back").val();
					parent.eval(call_back_value)(data); 
					var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
			        parent.layer.close(index);
					//return data;
				}
		}
		$.getResourceLive(param)
	})
	
	$('body').on('click','#cancel_submit',function(e){
			window.localStorage.clear();
            parent.closeSourceBox();
	})
	
	
	$.extend({
		getResource : function (option) {
			var chosed_video_ids = $("#chosed_video_ids").val();
			chosed_video_ids_arr=chosed_video_ids.split(",");
			chosed_video_ids_arr.pop();
			
			var chosed_video_names = $("#chosed_video_names").val();
			chosed_video_names_arr=chosed_video_names.split(",");
			chosed_video_names_arr.pop();
			
			var chosed_video_urls = $("#chosed_video_urls").val();
			chosed_video_urls_arr=chosed_video_urls.split("~");
			chosed_video_urls_arr.pop();
			
			var chosed_video_thumbnail_urls = $("#chosed_video_thumbnail_urls").val();
			chosed_video_thumbnail_urls_arr=chosed_video_thumbnail_urls.split("~");
			
			var chosed_video_file_ids = $("#chosed_video_file_ids").val();
			chosed_video_file_ids_arr=chosed_video_file_ids.split(",");
			chosed_video_file_ids_arr.pop();
			
			var chosed_video_durations = $("#chosed_video_durations").val();
			chosed_video_durations_arr=chosed_video_durations.split(",");
			chosed_video_durations_arr.pop();
			
			var chosed_video_heights = $("#chosed_video_heights").val();
			chosed_video_heights_arr=chosed_video_heights.split(",");
			chosed_video_heights_arr.pop();
			
			var chosed_video_widths = $("#chosed_video_widths").val();
			chosed_video_widths_arr=chosed_video_widths.split(",");
			chosed_video_widths_arr.pop();
			
			var chosed_video_sizes = $("#chosed_video_sizes").val();
			chosed_video_sizes_arr=chosed_video_sizes.split(",");
			chosed_video_sizes_arr.pop();
			
			
			var chosed_img_ids = $("#chosed_img_ids").val();
			chosed_img_ids_arr=chosed_img_ids.split(",");
			chosed_img_ids_arr.pop();
			
			var chosed_img_names = $("#chosed_img_names").val();
			chosed_img_names_arr=chosed_img_names.split(",");
			chosed_img_names_arr.pop();
			
			var chosed_img_urls = $("#chosed_img_urls").val();
			chosed_img_urls_arr=chosed_img_urls.split("~");
			chosed_img_urls_arr.pop();
			var videoData = [];
			var imageData = [];
			$.each(chosed_img_urls_arr, function (i){
			    imageData.push({
			        name: chosed_img_names_arr[i],
			        url: chosed_img_urls_arr[i],
			        id: chosed_img_ids_arr[i]
			    });
			})
			$.each(chosed_video_urls_arr,function (i) {
			    videoData.push({
			        id: chosed_video_ids_arr[i],
			        name: chosed_video_names_arr[i],
			        url: chosed_video_urls_arr[i],
			        poster: chosed_video_thumbnail_urls_arr[i],
			        file_id: chosed_video_file_ids_arr[i],
			        duration: chosed_video_durations_arr[i],
			        height: chosed_video_heights_arr[i],
			        width: chosed_video_widths_arr[i],
			        size: chosed_video_sizes_arr[i]
			    });
			})

			var data = {
					chosed_video_ids:chosed_video_ids_arr,
					chosed_video_names:chosed_video_names_arr,
					chosed_video_urls:chosed_video_urls_arr,
					chosed_video_thumbnail_urls:chosed_video_thumbnail_urls_arr,
					chosed_img_ids:chosed_img_ids_arr,
					chosed_img_names:chosed_img_names_arr,
					chosed_img_urls:chosed_img_urls_arr,
					chosed_video_file_ids:chosed_video_file_ids_arr,
					chosed_video_durations:chosed_video_durations_arr,
					chosed_video_heights:chosed_video_heights_arr,
					chosed_video_widths:chosed_video_widths_arr,
					chosed_video_sizes:chosed_video_sizes_arr,
					videos: videoData,
					images: imageData
			} 
			if (option.success && typeof(option.success) == "function") {
				console.log(data)
				option.success(data);
			}		
		}	
	});
	
	$.extend({
		getResourceNews : function (option) {
			var chosed_news_ids = $("#chosed_news_ids").val();
			chosed_news_ids_arr=chosed_news_ids.split(",");
			chosed_news_ids_arr.pop();
			
			var chosed_news_names = $("#chosed_news_names").val();
			chosed_news_names_arr=chosed_news_names.split(",");
			chosed_news_names_arr.pop();
			
			var chosed_news_urls = $("#chosed_news_urls").val();
			chosed_news_urls_arr=chosed_news_urls.split("~");
			chosed_news_urls_arr.pop();
			
			var data = {
					chosed_news_ids:chosed_news_ids_arr,
					chosed_news_names:chosed_news_names_arr,
					chosed_news_urls:chosed_news_urls_arr
			} 
			if (option.success && typeof(option.success) == "function") {
				console.log(data)
				option.success(data);
			}		
		}	
	});
	
	$.extend({
		getResourceLive : function (option) {
			var chosed_live_ids = $("#chosed_live_ids").val();
			chosed_live_ids_arr=chosed_live_ids.split(",");
			chosed_live_ids_arr.pop();
			
			var chosed_live_names = $("#chosed_live_names").val();
			chosed_live_names_arr=chosed_live_names.split(",");
			chosed_live_names_arr.pop();
			
			var chosed_live_urls = $("#chosed_live_urls").val();
			chosed_live_urls_arr=chosed_live_urls.split("~");
			chosed_live_urls_arr.pop();
			
			var data = {
					chosed_live_ids:chosed_live_ids_arr,
					chosed_live_names:chosed_live_names_arr,
					chosed_live_urls:chosed_live_urls_arr
			} 
			if (option.success && typeof(option.success) == "function") {
				console.log(data)
				option.success(data);
			}		
		}	
	});
});
	
function open_resource_href(type='',call_back = 'getResources', set_water = '0', chosed_resource_ids='', admin_id = ''){
//	window.localStorage.clear();exit;
	  var data_list=window.localStorage;

	  layer.open({
		    type: 2,
		    //skin: 'layui-layer-lan',
		    title: '资源池',
		    fix: false,
		    shadeClose: true,
		    maxmin: true,
		    area: ['1200px', '670px'],
		    content: "./index.php?g=Admin&m=Resources&a=resource_library&show_type=2&type="+type+"&call_back="+call_back+"&set_water="+set_water+"&chosed_resource_ids="+chosed_resource_ids,
		    end: function(){
		    	window.localStorage.clear();
		    }
	});
}

//打开新闻资源
function open_resource_news_href(call_back = 'getResourcesNews', chosed_resource_ids=''){
	  layer.open({
		    type: 2,
		    //skin: 'layui-layer-lan',
		    title: '资源池',
		    fix: false,
		    shadeClose: true,
		    maxmin: true,
		    area: ['1200px', '670px'],
		    content: "./index.php?g=Admin&m=Resources&a=resource_library_news&call_back="+call_back+"&chosed_resource_ids="+chosed_resource_ids,
		    end: function(){
		}
	});
}

//打开直播资源
function open_resource_live_href(call_back = 'getResourcesLive', chosed_resource_ids=''){
	  layer.open({
		    type: 2,
		    //skin: 'layui-layer-lan',
		    title: '资源池',
		    fix: false,
		    shadeClose: true,
		    maxmin: true,
		    area: ['1200px', '670px'],
		    content: "./index.php?g=Admin&m=Resources&a=resource_library_live&call_back="+call_back+"&chosed_resource_ids="+chosed_resource_ids,
		    end: function(){
		}
	});
}



